package kafka

import (
	"context"
	"github.com/segmentio/kafka-go"
	"trpg-common/config"
	"trpg-common/logger"
)

func WriteByConn(message []byte) {
	writer := &kafka.Writer{
		Addr:     kafka.TCP(config.GetString("kafka.address")),
		Topic:    config.GetString("kafka.topic"),
		Balancer: &kafka.LeastBytes{},
	}
	defer writer.Close()
	err := writer.WriteMessages(context.Background(), kafka.Message{Value: message})
	if err != nil {
		logger.Logger.Panicf("failed to write messages: %+v", err)
	}
}
